﻿using Commerce_phuc.Models.Entity;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Commerce_phuc.Areas.Kuku.Controllers
{
    public class QuanAoController : Controller
    {
        // GET: Kuku/QuanAo
        Entity db = new Entity();
        public ActionResult Index()
        {
            var a = db.ProductQuanAos;
            return View(a);
        }
        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(ProductQuanAo model)
        {

            try
            {
                db.ProductQuanAos.Add(model);
                db.SaveChanges();
                ModelState.AddModelError("", "Cập nhật thành công !");
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                return View("Index", model);

            }

        }

        public ActionResult Edit(int id)
        {

            var model = db.ProductQuanAos.Find(id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(ProductQuanAo model)
        {
            try
            {
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                ModelState.AddModelError("", "Cập nhật Thành Công");

            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

            }

            return RedirectToAction("Index", model);
        }
        public ActionResult Delete(int Id)
        {
            var model = db.ProductQuanAos.Find(Id);
            db.ProductQuanAos.Remove(model);
            db.SaveChanges();
            return RedirectToAction("Index");
        }


       

    }
}